<?php
/*
PluginName:友情链接
PluginUrl:http://www.lisijie.org
PluginAuthor:lisijie
PluginAuthorUrl:http://www.lisijie.org
PluginDesc:显示您的博客友情链接
PluginVer:2.0.0
*/

class FriendlinkWidget extends Widget {
	
	function FriendlinkWidget() {
		$options = array(
			'title' => '友情链接',
			'cates' => array(),
			'showtype' => 1
		);
		$this->Widget($options);
	}
	
	//设置面板
	function setting() {
		global $_CACHE;
		echo '<p>显示标题：<input type="text" name="title" value="'.$this->get_option('title').'" /></p>';
		echo '<p>显示分类：</p>';
		echo '<p>';
		foreach ( (array)$_CACHE['cate']['link'] as $cid ) {
			$cate = $_CACHE['cate'][$cid];
			$checked = '';
			if ( in_array($cid, $this->get_option('cates')) ) {
				$checked = 'checked';
			}
			echo '<input type="checkbox" class="checkbox" name="cates[]" value="'.$cid.'" id="cate_'.$cid.'" '.$checked.' /><label for="cate_'.$cid.'">'.$cate['catename'].'</label> ';
		}
		echo '</p>';	
	}
	
	function update($data) {
		if ( empty($data['title']) ) {
			$data['title'] = '友情链接';
		}
		$data['showtype'] = $data['showtype']==2?2:1;
		return $data;
	}
	
	function display() {
		if ( $this->get_option('cates')  ) {
			global $_CACHE;
			get_cache('link');
			$data = '';
			foreach ( $this->get_option('cates') as $cid ) {
				foreach ( (array)$_CACHE['link'][$cid]['links'] as $link ) {
					if ( !empty($link['logo']) ) {
						$txt = '<img src="'.$link['logo'].'" alt="'.$link['name'].'"/>';
					} else {
						$txt = $link['name'];
					}
					$data .= '<li><a href="'.$link['url'].'" target="_blank" title="'.($link['description']?$link['description']:$link['name']).'">'.$txt.'</a></li>'."\n";
				}
			}
		}
		return "<ul>$data</ul>";
	}
}
?>